import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  const uname = ref("");
  const uid = ref("");
  const pwd = ref("");
  const identity = ref("");
  const phone = ref("13800000000");
  const email = ref("123456789@qq.com")

  let setUname = function(str){
    uname.value = str;
    localStorage.setItem("uname",uname.value);
  }

  let setUid = function(str){
    uid.value = str;
    localStorage.setItem("uid",uid.value);
  }

  let setPwd = function(str){
    pwd.value = str;
    localStorage.setItem("pwd",pwd.value);
  }

  let setIdentity = function(str){
    identity.value = str;
    localStorage.setItem("identity",identity.value);
  }

  let setPhone = function(str){
    phone.value = str;
    localStorage.setItem("phone",phone.value);
  }

  let setEmail = function(str){
    email.value = str;
    localStorage.setItem("email",email.value);
  }

  let storeInit = function(){
    uid.value = localStorage.getItem("uid");
    pwd.value = localStorage.getItem("pwd");
    identity.value = localStorage.getItem("identity");
    uname.value = localStorage.getItem("uname");
    phone.value = localStorage.getItem("phone");
    email.value = localStorage.getItem("email");
    console.log(`store初始化成功:${uname.value} ${uid.value} ${pwd.value} ${identity.value} ${phone.value} ${email.value}`);
  }

  return {
    uid,
    pwd,
    uname,
    identity,
    phone,
    email,
    setUid,
    setPwd,
    setIdentity,
    setUname,
    setPhone,
    setEmail,
    storeInit,
  }
})